import Cookies from 'js-cookie'
import { encode, decode } from './aesUtils'

const TokenKey = 'Admin-Token'

const ExpiresInKey = 'Admin-Expires-In'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  Cookies.remove('Common-Encrypt-Data', { path: '/' })
}

export function getExpiresIn() {
  return Cookies.get(ExpiresInKey) || -1
}

export function setExpiresIn(time) {
  return Cookies.set(ExpiresInKey, time)
}

export function removeExpiresIn() {
  return Cookies.remove(ExpiresInKey)
}

export function setTokenEncrypt(token) {
  if (token) Cookies.set('Common-Encrypt-Data', encode(token), { path: '/' })
}

export function getTokenDecrypt() {
  let token = Cookies.get('Common-Encrypt-Data')
  return decode(token)
}
